// pages/roomsList/roomsList.js
var common = require('../../utils/common.js');
const app = getApp();
var that = "";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // dataList: [{ name: 5, check: false }, { name: 6, check: false}]
    dataList: []
  },
  //点击右边的展开图标
  clickRIcon: function (e) {
    var index = e.currentTarget.dataset.index;
    this.data.dataList[index].check = !this.data.dataList[index].check;
    this.setData({
      dataList: this.data.dataList
    })
  },
  //点击费用项
  clickItem: function (e) {
    var index = e.currentTarget.dataset.index;
    wx.navigateTo({
      url: '../billAllHouse/billAllHouse?year=' + that.data.dataList[index].year + '&month=' + that.data.dataList[index].month
    })
  },
  //点击子费用项
  clickItemChild: function (e) {
    var index = e.currentTarget.dataset.index;
    var isyj = e.currentTarget.dataset.isyj;
    var key = e.currentTarget.dataset.key;
    var isreduce = e.currentTarget.dataset.isreduce;
    console.log(isreduce)
    wx.navigateTo({
      url: '../billChild/billChild?year=' + that.data.dataList[index].year + '&month=' + that.data.dataList[index].month + '&key=' + key + '&isyj=' + isyj + '&isreduce=' + isreduce,
    })
  },
  //获取费用
  getData: function () {
    common._get('/wx/landlord/charge/month/list', {},
      //成功
      function (res) {
        console.log(res.data)
        if (res.data.success) {
          for (var i in res.data.data) {
            if (i == 0) {
              res.data.data[i].check = true;
            } else {
              res.data.data[i].check = false;
            }
          }
          that.setData({
            dataList: res.data.data
          })
        }
      });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that = this;
    this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var addContract = wx.getStorageSync('addContract');
    if (addContract) {
      this.getData();
    }
    if(app.getRefresh()){
      this.getData();
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getData();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})